//Copyright  2015 Max "Shrinker" Wieden
//Refer to license for license details.

//this grammar matches Microbrush 3 .mb3txt files
Tokens:
	Name                 = FirstNameChar (FirstNameChar | Digit)*;
	FloatLiteral         = [['+', '-']] (BaseFloatLiteral [FloatExponent] | NumericLiteral FloatExponent);
	#FloatExponent       = ['E', 'e'] [['+', '-']] (Digit)+;
	IntLiteral           = [['+', '-']] NumericLiteral;
	Comma                = ',';
	LBracket             = '[';
	LPar                 = '(';
	RBracket             = ']';
	RPar                 = ')';
	#FirstNameChar       = ['A'-'Z'] | ['a'-'z'] | ['_', '$'];
	#Digit               = ['0'-'9'];
	#NumericLiteral      = '0' | ['1'-'9'] (Digit)*;
	#BaseFloatLiteral    = (Digit)+ '.' (Digit)* | '.' (Digit)+;

FillerTokens:
	Whitespace = (['\t', ' ', '\r', '\n'])+;

TokenSpecializations:
	KeyAnchors          = Name("anchors"         );
	KeyBrush            = Name("brush"           );
	KeyComputedFeatures = Name("computedFeatures");
	KeyFalse            = Name("false"           );
	KeyNormals          = Name("normals"         );
	KeyPatch9           = Name("patch9"          );
	KeyPlane            = Name("plane"           );
	KeyPoints           = Name("points"          );
	KeyPolygon          = Name("polygon"         );
	KeyTrue             = Name("true"            );
	KeyWorld            = Name("world"           );

Rules:
Start = {
	World
	EOF
}

World = {
	KeyWorld
	LPar
	KeyComputedFeatures (KeyFalse | KeyTrue)
	(Brush | Patch9)*
	RPar
}

Brush = {
	KeyBrush
	LPar
	(Plane)*
	RPar
}

Plane = {
	KeyPlane
	LPar
	#Vec3Coords Comma
	#Vec3Coords Comma
	#Vec3Coords
	[KeyPolygon Vec3List]
	RPar
}

Patch9 = {
	KeyPatch9
	LPar
	IntLiteral IntLiteral IntLiteral IntLiteral
	KeyAnchors Vec3List
	[
		KeyPoints  Vec3List
		KeyNormals Vec3List
	]
	RPar
}

Vec3List = {
	LBracket [#Vec3Coords (Comma #Vec3Coords)*] RBracket
}

#Vec3Coords = {
	(IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral) (IntLiteral | FloatLiteral)
}
